package com.huangjue.backend.service.impl;

import com.huangjue.backend.entity.Video;
import com.huangjue.backend.mapper.VideoMapper;
import com.huangjue.backend.service.VideoService;
import com.huangjue.backend.mapper.HomeworkMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import java.util.HashMap;

@Service
public class VideoServiceImpl implements VideoService {
    @Autowired
    private VideoMapper videoMapper;

    @Autowired
    private HomeworkMapper homeworkMapper;

    @Override
    public List<Video> getVideosByDemoId(Integer demoId) {
        return videoMapper.selectVideosByDemoId(demoId);
    }

    @Override
    public List<Video> getVideosWithHomeworkFlagByDemoId(Integer demoId) {
        List<Video> videos = videoMapper.selectVideosByDemoId(demoId);
        for (Video video : videos) {
            int count = homeworkMapper.countByVideoId(video.getVideoId());
            video.setHasHomework(count > 0);
        }
        return videos;
    }
} 